package com.example.lib_mvp.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.viewpager.widget.ViewPager;

//禁止滑动的viewpager
public class NoSwipeViewPager extends ViewPager {

    private boolean scrollable;

    public NoSwipeViewPager(Context context) {
        super(context);
        scrollable = true;
    }

    public NoSwipeViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
        scrollable = true;
    }

    public void setScrollable(boolean scrollable) {
        this.scrollable = scrollable;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return scrollable && super.onTouchEvent(event);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        return scrollable && super.onInterceptTouchEvent(event);
    }

    /**
     * 去除页面切换时的滑动翻页效果
     *
     * @param item
     */
    @Override
    public void setCurrentItem(int item) {
        super.setCurrentItem(item, false);
    }

    /**
     * 去除页面切换时的滑动翻页效果
     *
     * @param item
     * @param smoothScroll
     */
    @Override
    public void setCurrentItem(int item, boolean smoothScroll) {
        super.setCurrentItem(item, smoothScroll);
    }
}

